package com.aspose.cells;

import java.util.Iterator;

class zeb extends zbz {
   private FormatCondition a;

   zeb() {
      this.c(2170);
   }

   void a(zxt var1) {
      this.a = var1.a;
      int var2 = 18;
      byte[] var3 = null;
      byte[] var4 = null;
      byte var5;
      switch(this.a.getType()) {
      case 0:
         var5 = 1;
         this.a.f();
         var3 = this.a.a();
         var4 = this.a.c();
         break;
      case 1:
      default:
         var5 = 2;
         if (var1.f != null) {
            var3 = var1.f;
         } else {
            this.a.f();
            var3 = this.a.a();
         }
         break;
      case 2:
         var5 = 3;
         var2 += this.a(this.a.getColorScale());
         break;
      case 3:
         var5 = 4;
         var2 += this.a(this.a.getDataBar());
         break;
      case 4:
         var5 = 6;
         var2 += this.a(this.a.getIconSet());
         break;
      case 5:
         var5 = 5;
         var2 += 6;
      }

      if (var3 != null) {
         var2 += var3.length - 2;
         if (var4 != null) {
            var2 += var4.length - 2;
         }
      }

      var2 += var1.c();
      var2 += 24;
      this.a((short)var2);
      this.c = new byte[var2];
      this.c[0] = 122;
      this.c[1] = 8;
      byte var6 = 12;
      this.c[var6] = var5;
      this.c[var6 + 1] = zed.a(var5 != 1 ? 6 : this.a.getOperator());
      int var7 = var6 + 2;
      if (var3 != null) {
         System.arraycopy(com.aspose.cells.b.a.zc.a((short)(var3.length - 2)), 0, this.c, var7, 2);
         if (var4 != null) {
            System.arraycopy(com.aspose.cells.b.a.zc.a((short)(var4.length - 2)), 0, this.c, var7 + 2, 2);
         }
      }

      var7 += 4;
      var7 = a(var1.d, var1.c, this.c, var7);
      if (var3 != null) {
         System.arraycopy(var3, 2, this.c, var7, var3.length - 2);
         var7 += var3.length - 2;
         if (var4 != null) {
            System.arraycopy(var4, 2, this.c, var7, var4.length - 2);
            var7 += var4.length - 2;
         }
      }

      var7 += 2;
      if (this.a.getStopIfTrue()) {
         this.c[var7] = 2;
      }

      ++var7;
      System.arraycopy(com.aspose.cells.b.a.zc.a(this.a.getPriority()), 0, this.c, var7, 2);
      var7 += 2;
      System.arraycopy(com.aspose.cells.b.a.zc.a(a(this.a)), 0, this.c, var7, 2);
      var7 += 2;
      var7 = a(this.a, this.c, var7);
      switch(this.a.getType()) {
      case 2:
         this.a(this.a.getColorScale(), this.c, var7);
         break;
      case 3:
         this.a(this.a.getDataBar(), this.c, var7);
         break;
      case 4:
         this.a(this.a.getIconSet(), this.c, var7);
         break;
      case 5:
         a(this.a.getTop10(), this.c, var7);
      }

   }

   static int a(zrw var0, zbvr var1, byte[] var2, int var3) {
      int var4 = var3 + 4;
      int var5 = var4;
      if (var0 != null) {
         System.arraycopy(var0.e(), 0, var2, var4, var0.d());
         var4 += var0.d();
      }

      if (var1 != null) {
         var2[var4 + 2] = -1;
         var2[var4 + 3] = -1;
         var4 += 6;
         System.arraycopy(com.aspose.cells.b.a.zc.a(var1.getCount()), 0, var2, var4, 2);
         var4 += 2;
         var4 = zbvq.a(var1, var2, var4);
      }

      if (var4 > var5) {
         System.arraycopy(com.aspose.cells.b.a.zc.a(var4 - var5), 0, var2, var5 - 4, 4);
      } else {
         var4 += 2;
      }

      return var4;
   }

   static int a(FormatCondition var0) {
      switch(var0.getType()) {
      case 0:
         return 0;
      case 1:
         return 1;
      case 2:
         return 2;
      case 3:
         return 3;
      case 4:
         return 4;
      case 5:
         return 5;
      case 6:
         return 7;
      case 7:
         return 27;
      case 8:
      case 9:
      case 10:
      case 11:
         return 8;
      case 12:
         return 9;
      case 13:
         return 10;
      case 14:
         return 11;
      case 15:
         return 12;
      case 16:
         switch(var0.getTimePeriod()) {
         case 0:
            return 15;
         case 1:
            return 17;
         case 2:
            return 16;
         case 3:
            return 18;
         case 4:
            return 24;
         case 5:
            return 19;
         case 6:
            return 20;
         case 7:
            return 21;
         case 8:
            return 23;
         case 9:
            return 22;
         }
      default:
         return 1;
      case 17:
         AboveAverage var1 = var0.getAboveAverage();
         if (var1.isAboveAverage()) {
            return var1.isEqualAverage() ? 29 : 25;
         } else {
            return var1.isEqualAverage() ? 30 : 26;
         }
      }
   }

   static int a(FormatCondition var0, byte[] var1, int var2) {
      var1[var2] = 16;
      ++var2;
      switch(var0.getType()) {
      case 5:
         Top10 var6 = var0.getTop10();
         byte var4 = 0;
         if (!var6.isBottom()) {
            var4 = (byte)(var4 | 1);
         }

         if (var6.isPercent()) {
            var4 = (byte)(var4 | 2);
         }

         var1[var2] = var4;
         System.arraycopy(com.aspose.cells.b.a.zc.a((short)var6.getRank()), 0, var1, var2 + 1, 2);
      case 6:
      case 7:
      case 12:
      case 13:
      case 14:
      case 15:
      default:
         break;
      case 8:
         var1[var2] = 0;
         break;
      case 9:
         var1[var2] = 1;
         break;
      case 10:
         var1[var2] = 2;
         break;
      case 11:
         var1[var2] = 3;
         break;
      case 16:
         byte var5 = 0;
         switch(var0.getTimePeriod()) {
         case 0:
            var5 = 0;
            break;
         case 1:
            var5 = 1;
            break;
         case 2:
            var5 = 6;
            break;
         case 3:
            var5 = 2;
            break;
         case 4:
            var5 = 9;
            break;
         case 5:
            var5 = 5;
            break;
         case 6:
            var5 = 8;
            break;
         case 7:
            var5 = 3;
            break;
         case 8:
            var5 = 4;
            break;
         case 9:
            var5 = 7;
         }

         System.arraycopy(com.aspose.cells.b.a.zc.a((short)var5), 0, var1, var2, 2);
         break;
      case 17:
         AboveAverage var3 = var0.getAboveAverage();
         System.arraycopy(com.aspose.cells.b.a.zc.a((short)var3.getStdDev()), 0, var1, var2, 2);
      }

      return var2 + 16;
   }

   private int a(DataBar var1) {
      byte var2 = 22;
      int var3 = var2 + this.a(var1.a);
      var3 += this.a(var1.b);
      return var3;
   }

   private int a(DataBar var1, byte[] var2, int var3) {
      int var4 = var3 + 3;
      if (!var1.getShowValue()) {
         var2[var4] = (byte)(var2[var4] | 2);
      }

      ++var4;
      var2[var4] = 10;
      var2[var4 + 1] = 90;
      var4 += 2;
      var4 = a(var1.b(), var2, var4);
      var4 = a(var1.getMinCfvo(), var2, var4);
      var4 = a(var1.getMaxCfvo(), var2, var4);
      return var4;
   }

   private int a(ColorScale var1) {
      byte var2 = 6;
      int var4 = var2 + this.a(var1.a) + 32;
      boolean var3 = var1.a();
      if (var3) {
         var4 += this.a(var1.b) + 32;
      }

      var4 += this.a(var1.c) + 32;
      return var4;
   }

   private int a(ColorScale var1, byte[] var2, int var3) {
      int var4 = var3 + 3;
      boolean var5 = var1.a();
      var2[var4] = (byte)(var5 ? 3 : 2);
      var2[var4 + 1] = var2[var4];
      var4 += 2;
      var2[var4] = 3;
      ++var4;
      var4 = a(var1.getMinCfvo(), var2, var4);
      var4 += 8;
      if (var5) {
         var4 = a(var1.getMidCfvo(), var2, var4);
         System.arraycopy(com.aspose.cells.b.a.zc.a(0.5D), 0, var2, var4, 8);
         var4 += 8;
      }

      var4 = a(var1.getMaxCfvo(), var2, var4);
      System.arraycopy(com.aspose.cells.b.a.zc.a(1.0D), 0, var2, var4, 8);
      var4 += 8;
      var4 += 8;
      var4 = a(var1.d, var2, var4);
      if (var5) {
         System.arraycopy(com.aspose.cells.b.a.zc.a(0.5D), 0, var2, var4, 8);
         var4 += 8;
         var4 = a(var1.e, var2, var4);
      }

      System.arraycopy(com.aspose.cells.b.a.zc.a(1.0D), 0, var2, var4, 8);
      var4 += 8;
      var4 = a(var1.f, var2, var4);
      return var4;
   }

   private int a(IconSet var1) {
      int var2 = 6;
      ConditionalFormattingValue var4;
      if (var1.getCfvos().getCount() > 0) {
         for(Iterator var3 = var1.getCfvos().iterator(); var3.hasNext(); var2 += this.a(var4) + 5) {
            var4 = (ConditionalFormattingValue)var3.next();
         }
      }

      return var2;
   }

   private int a(IconSet var1, byte[] var2, int var3) {
      int var4 = var3 + 3;
      var2[var4] = (byte)var1.getCfvos().getCount();
      ++var4;
      var2[var4] = (byte)zsk.f(var1.getType());
      ++var4;
      if (!var1.getShowValue()) {
         var2[var4] = (byte)(var2[var4] | 1);
      }

      if (var1.getReverse()) {
         var2[var4] = (byte)(var2[var4] | 4);
      }

      ++var4;
      int var5 = zase.W(var1.getType());
      if (var1.getCfvos().getCount() < var5) {
         throw new CellsException(3, com.aspose.cells.b.a.zr.a(this.a((StringBuilder)null).append("Need more CFVO for IconSet")));
      } else {
         for(int var6 = 0; var6 < var5; ++var6) {
            ConditionalFormattingValue var7 = var1.getCfvos().get(var6);
            var4 = a(var7, var2, var4);
            if (var7.isGTE()) {
               var2[var4] = 1;
            }

            var4 += 5;
         }

         return var4;
      }
   }

   private static int a(Top10 var0, byte[] var1, int var2) {
      var1[var2] = 4;
      int var3 = var2 + 3;
      if (!var0.isBottom()) {
         var1[var3] = (byte)(var1[var3] | 1);
      }

      if (var0.isPercent()) {
         var1[var3] = (byte)(var1[var3] | 2);
      }

      ++var3;
      System.arraycopy(com.aspose.cells.b.a.zc.a((short)var0.getRank()), 0, var1, var3, 2);
      var3 += 2;
      return var3;
   }

   private int a(ConditionalFormattingValue var1) {
      switch(var1.getType()) {
      case 0:
      case 3:
      case 4:
      case 5:
         if (var1.e()) {
            if (var1.f() == null) {
               throw new CellsException(3, com.aspose.cells.b.a.zr.a(this.a((StringBuilder)null).append("Invalid formula for CFVO")));
            }

            if (var1.f().length > 2) {
               return 1 + var1.f().length;
            }
         }

         return 11;
      case 1:
      case 2:
      case 6:
      case 7:
         return 3;
      default:
         return 0;
      }
   }

   private static int a(ConditionalFormattingValue var0, byte[] var1, int var2) {
      int var3 = var2;
      switch(var0.getType()) {
      case 0:
         var1[var2] = 7;
         var3 = var2 + 1;
         var3 = b(var0, var1, var3);
         break;
      case 1:
      case 6:
         var1[var2] = 3;
         var3 = var2 + 3;
         break;
      case 2:
      case 7:
         var1[var2] = 2;
         var3 = var2 + 3;
         break;
      case 3:
         var1[var2] = 1;
         var3 = var2 + 1;
         var3 = b(var0, var1, var3);
         break;
      case 4:
         var1[var2] = 4;
         var3 = var2 + 1;
         var3 = b(var0, var1, var3);
         break;
      case 5:
         var1[var2] = 5;
         var3 = var2 + 1;
         var3 = b(var0, var1, var3);
      }

      return var3;
   }

   private static int b(ConditionalFormattingValue var0, byte[] var1, int var2) {
      if (var0.e() && var0.f() != null && var0.f().length > 2) {
         System.arraycopy(var0.f(), 0, var1, var2, var0.f().length);
         return var2 + var0.f().length;
      } else {
         int var3 = var2 + 2;
         System.arraycopy(com.aspose.cells.b.a.zc.a(var0.d()), 0, var1, var3, 8);
         var3 += 8;
         return var3;
      }
   }

   static int a(zakp var0, byte[] var1, int var2) {
      int var3;
      switch(var0.b()) {
      case 0:
      case 1:
         return var2 + 16;
      case 2:
      default:
         var1[var2] = 2;
         var3 = var2 + 4;
         int var4 = var0.d();
         var1[var3] = (byte)((var4 & 16711680) >> 16);
         var1[var3 + 1] = (byte)((var4 & '\uff00') >> 8);
         var1[var3 + 2] = (byte)(var4 & 255);
         break;
      case 3:
         var1[var2] = 1;
         var3 = var2 + 4;
         System.arraycopy(com.aspose.cells.b.a.zc.a(var0.d()), 0, var1, var3, 4);
         break;
      case 4:
         var1[var2] = 3;
         var3 = var2 + 4;
         System.arraycopy(com.aspose.cells.b.a.zc.a(var0.d()), 0, var1, var3, 4);
      }

      var3 += 4;
      System.arraycopy(com.aspose.cells.b.a.zc.a(var0.f()), 0, var1, var3, 8);
      var3 += 8;
      return var3;
   }

   private StringBuilder a(StringBuilder var1) {
      CellArea var2 = (CellArea)this.a.a.b.get(0);
      if (var1 == null) {
         var1 = new StringBuilder();
      }

      var1.append("FormatCondition at [").append(this.a.a.a.b.getName()).append("!");
      var1.append(CellsHelper.cellIndexToName(var2.StartRow, var2.StartColumn));
      var1.append(":");
      var1.append(CellsHelper.cellIndexToName(var2.EndRow, var2.EndColumn));
      var1.append("]:");
      return var1;
   }
}
